﻿

using Maticsoft.BLL;
using Maticsoft.Model;

using System;
using System.IO;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class WebPage_ShangHu_Create : SystemBBasePage
{

    private Maticsoft.BLL.Category cateGory = new Maticsoft.BLL.Category();
    private Maticsoft.Model.Category categoryModel = new Maticsoft.Model.Category();
 

    private void createBesinse()
    {
        int num;
        string str3;
        string str4;
        Exception exception;
        Maticsoft.Model.Partner model = new Maticsoft.Model.Partner();
        model.Username = this.username.Value;
        model.Password = PassWord.MD5(this.pwd.Value);
        if (this.SelectOne.SelectedItem.Value != "")
        {
            model.City_id = Convert.ToInt32(this.SelectOne.SelectedItem.Value);
        }
        if (this.SelectTwo.SelectedItem.Value != "")
        {
            model.Group_id = Convert.ToInt32(this.SelectTwo.SelectedItem.Value);
        }
        if (this.shangwuxiu.Value != string.Empty)
        {
            model.Open = this.shangwuxiu.Value.ToUpper();
        }
        else
        {
            model.Open = "N";
        }
        if ((this.FileUpload1.FileName != null) && (this.FileUpload1.FileName.ToString() != ""))
        {
            if (this.FileUpload1.PostedFile.ContentLength > 0x7d000)
            {
                this.SetError("请上传 512KB 以内的个人肖像图片!");
                return;
            }
            string fileName = this.FileUpload1.FileName;
            string str2 = "";
            if (this.FileUpload1.FileName != "")
            {
                num = fileName.LastIndexOf(".");
                str3 = fileName.Substring(num);
                str2 = DateTime.Now.Ticks.ToString() + 1 + str3;
            }
            try
            {
                if (fileName != "")
                {
                    str4 = base.Server.MapPath("~/upfile/user/");
                    if (!Directory.Exists(str4))
                    {
                        Directory.CreateDirectory(str4);
                    }
                    this.FileUpload1.PostedFile.SaveAs(str4 + str2);
                }
            }
            catch (Exception exception1)
            {
                exception = exception1;
                base.Response.Write(exception);
            }
            str2 = "/upfile/user/" + str2;
            model.Image = str2;
        }
        else
        {
            model.Image = "";
        }
        if ((this.FileUpload2.FileName != null) && (this.FileUpload2.FileName.ToString() != ""))
        {
            if (this.FileUpload2.PostedFile.ContentLength > 0x7d000)
            {
                this.SetError("请上传 512KB 以内的个人肖像图片!");
                return;
            }
            string str5 = this.FileUpload2.FileName;
            string str6 = "";
            if (this.FileUpload2.FileName != "")
            {
                num = str5.LastIndexOf(".");
                str3 = str5.Substring(num);
                str6 = DateTime.Now.Ticks.ToString() + 2 + str3;
            }
            try
            {
                if (str5 != "")
                {
                    str4 = base.Server.MapPath("~/upfile/user/");
                    this.FileUpload2.PostedFile.SaveAs(str4 + str6);
                }
            }
            catch (Exception exception2)
            {
                exception = exception2;
                base.Response.Write(exception);
            }
            str6 = "/upfile/user/" + str6;
            model.Image1 = str6;
        }
        else
        {
            model.Image1 = "";
        }
        if ((this.FileUpload3.FileName != null) && (this.FileUpload3.FileName != ""))
        {
            if (this.FileUpload3.PostedFile.ContentLength > 0x7d000)
            {
                this.SetError("请上传 512KB 以内的个人肖像图片!");
                return;
            }
            string str7 = this.FileUpload3.FileName;
            string str8 = "";
            if (this.FileUpload3.FileName != "")
            {
                num = str7.LastIndexOf(".");
                str3 = str7.Substring(num);
                str8 = DateTime.Now.Ticks.ToString() + 3 + str3;
            }
            try
            {
                if (str7 != "")
                {
                    str4 = base.Server.MapPath("~/upfile/user/");
                    this.FileUpload3.PostedFile.SaveAs(str4 + str8);
                }
            }
            catch (Exception exception3)
            {
                exception = exception3;
                base.Response.Write(exception);
            }
            str8 = "/upfile/user/" + str8;
            model.Image2 = str8;
        }
        else
        {
            model.Image2 = "";
        }
        model.Title = this.shangwuMingcheng.Value;
        model.Homepage = this.homepage.Value;
        model.Contact = this.contact.Value;
        model.Phone = this.phone.Value;
        model.Address = this.address.Value;
        model.Mobile = this.mobile.Value;
        model.Location = this.location.Value;
        model.Other = this.other.Value;
        model.Bank_name = this.bankname.Value;
        model.Bank_user = this.bankuser.Value;
        model.Bank_no = this.bankno.Value;
        Maticsoft.BLL.Partner partner2 = new Maticsoft.BLL.Partner();
        if (partner2.Add(model) > 0)
        {
            base.SetSuccess("添加成功！");
            base.Response.Redirect("ShangHu.aspx");
        }
        else
        {
            this.SetError("添加失败！");
            base.Response.Redirect("ShangHu.aspx");
        }
    }

    private void getBesinse()
    {
        StringBuilder builder = new StringBuilder();
        StringBuilder builder2 = new StringBuilder();
        ListItem item = new ListItem();
        item.Value = "0";
        item.Text = "全部城市";
        this.SelectOne.Items.Add(item);
        foreach (Maticsoft.Model.Category category in this.cateGory.GetModelList("Zone='city'"))
        {
            ListItem item2 = new ListItem();
            item2.Value = category.Id.ToString();
            item2.Text = category.Name.ToString();
            this.SelectOne.Items.Add(item2);
        }
        ListItem item3 = new ListItem();
        item3.Value = "";
        item3.Text = "----选择分类----";
        this.SelectTwo.Items.Add(item3);
        foreach (Maticsoft.Model.Category category in this.cateGory.GetModelList("Zone='partner'"))
        {
            ListItem item4 = new ListItem();
            item4.Value = category.Id.ToString();
            item4.Text = category.Name;
            this.SelectTwo.Items.Add(item4);
        }
        this.SelectOne.DataBind();
        this.SelectTwo.DataBind();
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "shanghu";
        if (!this.Page.IsPostBack)
        {
            this.getBesinse();
        }
    }

    protected void submit_ServerClick(object sender, EventArgs e)
    {
        this.createBesinse();
    }
}

